package com.jingogo.controller;

import com.jingogo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.jingogo.service.BillService;
import com.jingogo.service.UserService;
import com.jingogo.service.MetalRecyclingService;

@Slf4j
@RestController
@RequestMapping("/statistics")
@Tag(name = "数据统计", description = "数据统计与导出接口")
public class StatisticsController {
    @Autowired
    private BillService billService;
    @Autowired
    private UserService userService;
    @Autowired
    private MetalRecyclingService metalRecyclingService;

    @GetMapping("/sales")
    @Operation(summary = "销售数据统计", description = "销售数据统计")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<?> salesStatistics(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        // 示例：统计所有账单金额总和
        // 实际可根据startDate/endDate过滤
        return Result.success(billService.listBill());
    }

    @GetMapping("/user")
    @Operation(summary = "用户数据统计", description = "用户数据统计")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<?> userStatistics(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        // 示例：返回用户总数
        return Result.success(userService.getUserPage(1, 1000, null).getTotal());
    }

    @GetMapping("/recycling")
    @Operation(summary = "回收数据统计", description = "回收数据统计")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<?> recyclingStatistics(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        // 示例：返回回收订单数（假设有相关方法，暂用null）
        return Result.success(null);
    }

    @GetMapping("/export")
    @Operation(summary = "数据导出", description = "导出统计数据")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> exportStatistics(@RequestParam String type) {
        // 示例：导出统计数据
        return Result.success("导出成功");
    }
} 